//
//  AppDelegate.m
//  chart
//
//  Created by xu on 15/7/21.
//  Copyright (c) 2015年 xu. All rights reserved.
//

#import "AppDelegate.h"
#import "UIImage+RenderedImage.h"
#import "XGPushService.h"
#import "TSColor.h"
#import "TSLoginViewController.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [NSThread sleepForTimeInterval:3.0];//设置启动页面时间
    UIWindow *statusBarMaskWindow = [[UIWindow alloc] initWithFrame:[UIApplication sharedApplication].statusBarFrame];
    statusBarMaskWindow.backgroundColor = [UIColor clearColor];
    statusBarMaskWindow.windowLevel = UIWindowLevelStatusBar - 1.;
    [statusBarMaskWindow makeKeyAndVisible];
    
    /* 初始化导航条 */
    [self initNavBar];
    
    /*  初始化tabBar */
    [self initTabBarItem];
    
    _tabBarController = (TSTabBarController*)self.window.rootViewController;
    
    [XGPushService initWithOptions:launchOptions];
    
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//显示窗口配置
    
    TSLoginViewController *login = [[TSLoginViewController alloc] init];
    self.window.rootViewController = login;//配置window窗口的rootViewController实例
    //判定系统版本，选择页面加载方式
    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
    {
        [self.window addSubview:login.view];
    }
    else
    {
        [self.window setRootViewController:login];
    }
    [self.window makeKeyAndVisible];
    
    return YES;
}

- (void) initNavBar
{
    //统一导航条样式
    UIImage *navBarImage = [UIImage imageWithRenderColor:[TSColor mainColor] renderSize:CGSizeMake(10., 10.)];
    [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
    NSDictionary *textAttributes = @{
                                     NSFontAttributeName : FONT(18),
                                     NSForegroundColorAttributeName : [UIColor blackColor]
                                     };
    [[UINavigationBar appearance] setTitleTextAttributes:textAttributes];
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
}

- (void)initTabBarItem
{
    /* change color for tabBarItem.title */
//    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGB(162, 162, 162), NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    [XGPushService didReceiveLocalNotification:notification];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [XGPushService didReceiveRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    /* save device token */
    [TSTools setDeviceToken:deviceToken];
    
//    [XGPushService didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)applicationWillResignActive:(UIApplication *)application {

}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    
}

@end
